home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 66
/
Vol 66.iso
/
games
/
bluep.swf
/
scripts
/
__Packages
/
Music.as
< prev
next >
Wrap
Text File
|
2013-04-24
|
3KB
|
103 lines
class Music
{
function Music()
{
this.mySound = new Sound();
this.volume = 100;
this.currentTrack = "";
this.inCrossfade = false;
this.state = false;
this.changeSongs = true;
this.maxVolume = 60;
}
function SetMaxVolume(vol)
{
this.maxVolume = vol;
}
function SetTrack(setMusic)
{
trace(setMusic);
if(setMusic == this.currentTrack)
{
this.changeSongs = false;
}
else
{
this.changeSongs = true;
this.currentTrack = setMusic;
}
}
function Play()
{
this.mySound.stop();
this.mySound.attachSound(this.currentTrack);
this.volume = this.maxVolume;
this.mySound.setVolume(this.volume);
this.mySound.start(0,2000);
this.state = true;
}
function Stop()
{
this.mySound.stop();
this.state = false;
}
function PlayWithCrossFade(secondDuration)
{
if(this.changeSongs == true)
{
if(this.state == true)
{
this.inCrossfade = true;
this.targetVolume = 0;
var _loc2_ = secondDuration * 30;
this.volumeSpeed = (this.targetVolume - this.volume) / (_loc2_ / 2);
}
else
{
this.mySound.stop();
this.mySound.attachSound(this.currentTrack);
this.mySound.start(0,2000);
this.state = true;
this.inCrossfade = false;
this.targetVolume = this.maxVolume;
this.volume = 0;
this.mySound.setVolume(0);
_loc2_ = secondDuration * 30;
this.volumeSpeed = (this.targetVolume - this.volume) / _loc2_;
}
}
}
function RunPlayer()
{
if(this.targetVolume != this.volume)
{
var _loc2_ = undefined;
_loc2_ = this.volume + this.volumeSpeed;
if(this.volumeSpeed < 0 && _loc2_ < 0)
{
_loc2_ = 0;
}
else if(this.volumeSpeed > 0 && _loc2_ > this.targetVolume)
{
_loc2_ = this.targetVolume;
}
this.volume = _loc2_;
this.mySound.setVolume(_loc2_);
}
if(this.inCrossfade == true)
{
if(this.volume <= 0)
{
this.volumeSpeed *= -1;
this.inCrossfade = false;
this.targetVolume = this.maxVolume;
this.mySound.stop();
this.mySound.attachSound(this.currentTrack);
this.mySound.setVolume(0);
this.mySound.start(0,2000);
this.state = true;
}
}
}
}